package com.ledim.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import com.ledim.adapter.base.LedimBaseListAdapter;
import com.ledim.bean.RoomPlayVideoBean;
import com.ledim.utils.ConstantUtil;
import com.letv.android.young.client.R;
import java.util.ArrayList;

public class RoomPlayListAdapter extends LedimBaseListAdapter<RoomPlayVideoBean> {

    private int mWidth;

    public RoomPlayListAdapter(Context context, ArrayList<RoomPlayVideoBean> list) {
        super(context);
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        mWidth = wm.getDefaultDisplay().getWidth();
        setDatas(list);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_room_playlist_listview, null);
            holder.mName = (TextView) convertView.findViewById(R.id.item_room_play_name);
            holder.mState = (TextView) convertView.findViewById(R.id.item_room_play_state);
            holder.mMark = (ImageView) convertView.findViewById(R.id.item_room_play_mark);
            holder.mBg = convertView.findViewById(R.id.item_room_playlist_bg);
            holder.mName.setMaxWidth(mWidth / 4 * 3);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final RoomPlayVideoBean roomPlayVideoBean = getItem(position);

        if (roomPlayVideoBean.title != null && roomPlayVideoBean.title.length() > 0) {
            holder.mName.setText(roomPlayVideoBean.title);
        }
        holder.mBg.setBackgroundColor(Color.parseColor("#ffffff"));

            switch (roomPlayVideoBean.play_status) {
                case ConstantUtil.PlayState.wait:
                    holder.mState.setText("");
                    holder.mMark.setVisibility(View.GONE);
                    holder.mName.setTextColor(Color.parseColor("#666666"));
                    break;

                case ConstantUtil.PlayState.palying:
                    holder.mState.setText("放映中");
                    holder.mState.setTextColor(Color.parseColor("#1a1a1a"));
                    holder.mName.setTextColor(Color.parseColor("#1a1a1a"));
                    holder.mMark.setVisibility(View.VISIBLE);
                    holder.mBg.setBackgroundColor(Color.parseColor("#FEFBBD"));
                    break;

                case ConstantUtil.PlayState.end:
                    holder.mMark.setVisibility(View.GONE);
                    holder.mState.setText("已结束");
                    holder.mState.setTextColor(Color.parseColor("#999999"));
                    holder.mName.setTextColor(Color.parseColor("#999999"));
                    break;

                default:
                    holder.mState.setText("即将放映");
                    holder.mState.setTextColor(Color.parseColor("#1a1a1a"));
                    holder.mName.setTextColor(Color.parseColor("#1a1a1a"));
                    break;
            }
        return convertView;
    }

    public static class ViewHolder {

        private TextView mName;
        private TextView mState;
        private ImageView mMark;
        private View mBg;
    }
}
